<template>
  <div class="video-section">
    <div class="section-header">
      <h2 class="section-title">{{ title }}</h2>
      <div class="section-actions">
        <slot name="actions">
          <a href="#" class="section-more" @click.prevent="handleViewMore">{{ showMoreText || '更多' }}</a>
        </slot>
      </div>
    </div>
    
    <div class="video-grid">
      <VideoCard 
        v-for="video in videos" 
        :key="video.id" 
        :video="video" 
        @video-click="handleVideoClick"
      />
    </div>
    
    <div v-if="showLoadMore" class="section-footer">
      <button 
        class="load-more-btn" 
        :disabled="isLoading" 
        @click="handleLoadMore"
      >
        <i v-if="isLoading" class="fas fa-spinner fa-spin"></i>
        {{ isLoading ? '加载中...' : '加载更多' }}
      </button>
    </div>
  </div>
</template>

<script>
import VideoCard from './VideoCard.vue'

export default {
  name: 'VideoSection',
  components: {
    VideoCard,
  },
  props: {
    title: {
      type: String,
      required: true,
    },
    videos: {
      type: Array,
      default: () => [],
    },
    showMoreText: {
      type: String,
      default: null,
    },
    showLoadMore: {
      type: Boolean,
      default: false,
    },
    isLoading: {
      type: Boolean,
      default: false,
    },
  },
  methods: {
    handleVideoClick(videoId) {
      this.$emit('video-click', videoId)
    },
    handleViewMore() {
      this.$emit('view-more')
    },
    handleLoadMore() {
      this.$emit('load-more')
    },
  },
}
</script>

<style scoped>
.video-section {
  background: white;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid #f0f0f0;
}

.section-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title::before {
  content: '';
  width: 4px;
  height: 20px;
  background: linear-gradient(135deg, #ff6b6b, #ffaf40);
  border-radius: 2px;
}

.section-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-more {
  color: #1890ff;
  text-decoration: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: color 0.3s ease;
}

.section-more:hover {
  color: #40a9ff;
}

.section-more::after {
  content: '>';
  font-size: 12px;
  font-weight: 600;
  transition: transform 0.3s ease;
}

.section-more:hover::after {
  transform: translateX(2px);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}

.section-footer {
  margin-top: 20px;
  text-align: center;
}

.load-more-btn {
  padding: 10px 24px;
  background: #f0f2f5;
  border: none;
  border-radius: 6px;
  color: #333;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.load-more-btn:hover:not(:disabled) {
  background: #e6e8eb;
  transform: translateY(-2px);
}

.load-more-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* 响应式设计 */
@media (max-width: 1200px) {
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
  }
}

@media (max-width: 768px) {
  .video-section {
    padding: 16px;
  }
  
  .section-title {
    font-size: 16px;
  }
  
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 12px;
  }
}

@media (max-width: 480px) {
  .video-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .section-actions {
    display: none;
  }
}

/* 视频卡片在不同列数下的响应式调整 */
@media (min-width: 1600px) {
  .video-grid {
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  }
}
</style>